package com.controller;

import com.exception.UserNotExistException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.Arrays;

@Controller
public class HelloController {
    @RequestMapping("/hello")
    @ResponseBody
    public String hello(@RequestParam("user") String user) {
        if ("aaa".equals(user)) {
            throw new UserNotExistException();
        }
        return "hello";
    }

    @RequestMapping("/success")
    public ModelAndView success() {
        ModelAndView mv = new ModelAndView("success");
        mv.addObject("hello", "<h1>你好</h1>");
        mv.addObject("pass", "password");
        mv.addObject("users", Arrays.asList("张三", "李四", "王五"));
        return mv;
    }

}
